from rest_framework import serializers
from .models import *
from django.contrib.auth.hashers import make_password, check_password


class UserSer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = "__all__"

    def create(self, validated_data):
        validated_data["password"] = make_password(validated_data["password"])

        return User.objects.create(**validated_data)


class GoodsSer(serializers.ModelSerializer):
    class Meta:
        model = Goods
        fields = "__all__"


class CartSer(serializers.ModelSerializer):
    class Meta:
        model = Cart
        fields = "__all__"


class CartListSer(serializers.ModelSerializer):
    goods = GoodsSer()

    class Meta:
        model = Cart
        fields = "__all__"


class CouponSer(serializers.ModelSerializer):
    class Meta:
        model = Coupon
        fields = "__all__"


class UserCouponSer(serializers.ModelSerializer):
    coupon = CouponSer()

    class Meta:
        model = UserCoupon
        fields = "__all__"
